package com.ruoyi.assemble.flow.controller;

import com.didiglobal.turbo.engine.common.ErrorEnum;
import com.didiglobal.turbo.engine.param.StartProcessParam;
import com.didiglobal.turbo.engine.result.StartProcessResult;
import com.ruoyi.assemble.flow.pojo.request.GetFlowInstanceListRequest;
import com.ruoyi.assemble.flow.pojo.request.GetFlowModuleListRequest;
import com.ruoyi.assemble.flow.pojo.response.BaseResponse;
import com.ruoyi.assemble.flow.pojo.response.FlowModuleListResponse;
import com.ruoyi.assemble.flow.service.LeaveServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: ruoyi
 * @ClassName OrderController
 * @description: 说明：TODO
 * @author: yuqh
 * @create: 2023-02-25 13:32
 * @Version 1.0
 **/
@RestController
@RequestMapping("/logicorder")
public class OrderController {

    private static final Logger LOGGER = LoggerFactory.getLogger(FlowController.class);

    @Resource
    private LeaveServiceImpl leaveService;

    /**
     * 分页查询流程列表
     * @param getFlowInstanceListRequest  分页请求参数
     * @return 返回列表数据
     */
    @RequestMapping(value = "/queryOrderList", method = {RequestMethod.POST})
    public BaseResponse queryFlowList(@RequestBody GetFlowInstanceListRequest getFlowInstanceListRequest) {
        try{
            BaseResponse flowModuleListResponse = leaveService.getFlowOrderList(getFlowInstanceListRequest);
            BaseResponse baseResponse =  BaseResponse.make(flowModuleListResponse);
            baseResponse.setErrCode(ErrorEnum.SUCCESS.getErrNo());
            baseResponse.setErrMsg(ErrorEnum.SUCCESS.getErrMsg());
            return baseResponse;
        }catch(Exception e){
            LOGGER.error(" queryFlowInstanceList error",e);
            return  new BaseResponse<>(ErrorEnum.SYSTEM_ERROR);
        }
    }

    /**
     *  启动流程实例
     * @param startProcessParam
     * @return
     */
    @RequestMapping(value = "/startAndExecute", method = {RequestMethod.POST})
    public BaseResponse startAndExecute(@RequestBody StartProcessParam startProcessParam){
        StartProcessResult result = leaveService.startProcess(startProcessParam);
        BaseResponse baseResponse =  BaseResponse.make(result);
        baseResponse.setErrCode(ErrorEnum.SUCCESS.getErrNo());
        baseResponse.setErrMsg(ErrorEnum.SUCCESS.getErrMsg());
        return baseResponse;
    }
}
